package com.sports.demo.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sports.demo.basic.BasicController;
import com.sports.demo.model.Admin;
import com.sports.demo.model.User;
import com.sports.demo.service.AdminService;
import com.sports.demo.utils.AssertUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 管理员 前端控制器
 * </p>
 *
 * @author SRG
 * @since 2022-03-13
 */
@RestController
@RequestMapping("/admin")
public class AdminController extends BasicController<AdminService, Admin> {


  @ApiOperation(value="登录", notes="")
  @PostMapping("login")
  public Admin login(@RequestBody @Validated Admin admin) {
    AssertUtils.notBlank(admin.getName(),"登录名不能为空");
    AssertUtils.notBlank(admin.getPassword(),"密码不能为空");
    Admin user2 =getBasicService().getOne(Wrappers.lambdaQuery(Admin.class).
        eq(Admin::getName , admin.getName()));
    AssertUtils.notNull(user2,"用户不存在");
    Admin user1 =getBasicService().getOne(Wrappers.lambdaQuery(Admin.class).
        eq(Admin::getName , admin.getName()).eq(Admin::getPassword,admin.getPassword()));
    AssertUtils.notNull(user1,"密码错误");
    return user1;
  }

}
